package com.pi.config;




import com.pi.core.exchange.vo.CommonNameRegistryService;
import com.pi.pro.xcmg.am.common.XcmgAmConstants;
import com.pi.pro.xcmg.am.was.edi.infor.common.InforWasXcmgExchangeConstants;
import com.pi.pro.xcmg.am.was.edi.infor.service.StorageServiceProxy;
import com.pi.pro.xcmg.am.was.edi.infor.service.TaskServiceProxy;
import com.pi.wms.fac.conn.HttpAccessUrl;
import com.pi.wms.fac.conn.HttpclientProxy;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;



/**
 *
 */
@Configuration
public class InforWmsClientExchangeConfig {


    private Map<String, Map<String, String>> fullXwmsWasLocationMapping=new HashMap<>();

/**==================================================================================================================**/
//  WH101/
/**==================================================================================================================**/

    @Value("${xwms.api.was.wh101.code}")
    private String xwmsWh101ServiceCode;

    @Value("${xwms.api.was.wh101.warehousecode}")
    private String xwmsWh101Warehousecode;

    /**
    @Value("${xwms.api.was.wh101.token}")
    private String xwmsWh101Token;
    **/

    /**
     * STORAGE
     */
    @Value("${xwms.api.was.wh101.storage.client.code}")
    private String xwmsStorageWh101ClientCode;

    @Value("${xwms.api.was.wh101.storage.func.query.url}")
    private String xwmsStorageQueryWh101PostAccessUrl;


    /**
     * TASK
     */
    @Value("${xwms.api.was.wh101.task.client.code}")
    private String xwmsTaskWh101ClientCode;

    @Value("${xwms.api.was.wh101.task.func.report.url}")
    private String xwmsTaskReportWh101PostAccessUrl;


/**==================================================================================================================**/
//  all
/**==================================================================================================================**/

    @Bean
    public CommonNameRegistryService xwmsNameRegistryService(){
        CommonNameRegistryService nameRegistryService = new CommonNameRegistryService(InforWasXcmgExchangeConstants.XWMS_ENDPOINT_NAMESPACE);
        nameRegistryService.clientnMapping(XcmgAmConstants.clients);
        nameRegistryService.orgnizationMapping(XcmgAmConstants.organizations);
        return nameRegistryService;
    }





/**==================================================================================================================**/
//  WH101
/**==================================================================================================================**/

    /**********************************************/
    //** STORAGE
    /**********************************************/
    @Bean
    public HttpAccessUrl xwmsStorageQueryWh101PostAccessUrl(){
        HttpAccessUrl accessUrl=new HttpAccessUrl();
        accessUrl.setUrl(this.xwmsStorageQueryWh101PostAccessUrl);
        return accessUrl;
    }

    @Bean
    public HttpclientProxy xwmsStorageWh101Client(){
        HttpclientProxy client=new HttpclientProxy(this.xwmsStorageWh101ClientCode);
        return client;
    }

    @Bean
    public StorageServiceProxy xwmsStorageWh101ServiceProxy(){
        StorageServiceProxy proxy=new StorageServiceProxy();
        proxy.setCategory(this.xwmsWh101ServiceCode);
        proxy.setCode(this.xwmsWh101ServiceCode+this.xwmsStorageWh101ClientCode);
        proxy.setWmsStorageClient(this.xwmsStorageWh101Client());
        //proxy.setToken(this.xwmsWh101Token);
        proxy.setWmsStorageQueryPostAccessUrl(this.xwmsStorageQueryWh101PostAccessUrl());
        this.xwmsNameRegistryService().register(proxy);
        return proxy;
    }

    /**********************************************/
    //** Task
    /**********************************************/
    @Bean
    public HttpAccessUrl xwmsTaskReportWh101PostAccessUrl(){
        HttpAccessUrl accessUrl=new HttpAccessUrl();
        accessUrl.setUrl(this.xwmsTaskReportWh101PostAccessUrl);
        return accessUrl;
    }

    @Bean
    public HttpclientProxy xwmsTaskWh101Client(){
        HttpclientProxy client=new HttpclientProxy(this.xwmsTaskWh101ClientCode);
        return client;
    }

    @Bean
    public TaskServiceProxy xwmsTaskWh101ServiceProxy(){
        TaskServiceProxy proxy=new TaskServiceProxy();
        proxy.setCategory(this.xwmsWh101ServiceCode);
        proxy.setCode(this.xwmsWh101ServiceCode+this.xwmsTaskWh101ClientCode);
        proxy.setWmsTaskClient(this.xwmsTaskWh101Client());
        //proxy.setToken(this.xwmsWh101Token);
        proxy.setWmsTaskReportPostAccessUrl(this.xwmsTaskReportWh101PostAccessUrl());
        this.xwmsNameRegistryService().register(proxy);
        return proxy;
    }



}
